package com.mall.module.system.controller;

import com.github.pagehelper.PageInfo;
import com.mall.common.result.Result;
import com.mall.module.system.domain.entity.SysLoginLog;
import com.mall.module.system.service.SysLoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 系统登录日志控制器
 */
@Api(tags = "登录日志接口")
@RestController
@RequestMapping("/api/system/loginLog")
public class SysLoginLogController {
    
    @Autowired
    private SysLoginLogService loginLogService;
    
    /**
     * 获取登录日志列表
     */
    @ApiOperation(value = "获取登录日志列表")
    @GetMapping("/list")
    public Result<PageInfo<SysLoginLog>> list(
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页记录数", defaultValue = "10") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam(value = "用户名") @RequestParam(required = false) String username,
            @ApiParam(value = "状态") @RequestParam(required = false) Integer status,
            @ApiParam(value = "开始时间") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
            @ApiParam(value = "结束时间") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        PageInfo<SysLoginLog> pageInfo = loginLogService.listLoginLogPage(pageNum, pageSize, username, status, startTime, endTime);
        return Result.success(pageInfo);
    }
    
    /**
     * 获取登录日志详情
     */
    @ApiOperation(value = "获取登录日志详情")
    @GetMapping("/{id}")
    public Result<SysLoginLog> getInfo(@ApiParam(value = "日志ID", required = true) @PathVariable Long id) {
        SysLoginLog loginLog = loginLogService.getLoginLogById(id);
        return Result.success(loginLog);
    }
    
    /**
     * 删除登录日志
     */
//    @ApiOperation(value = "删除登录日志")
//    @DeleteMapping("/{id}")
//    public Result<Void> delete(@ApiParam(value = "日志ID", required = true) @PathVariable Long id) {
//        boolean result = loginLogService.deleteLoginLog(id);
//        return result ? Result.success() : Result.failed("删除登录日志失败");
//    }
//
//    /**
//     * 批量删除登录日志
//     */
//    @ApiOperation(value = "批量删除登录日志")
//    @DeleteMapping("/batch")
//    public Result<Void> batchDelete(@ApiParam(value = "日志ID数组", required = true) @RequestBody List<Long> ids) {
//        boolean result = loginLogService.deleteLoginLogByIds(ids);
//        return result ? Result.success() : Result.failed("批量删除登录日志失败");
//    }
//
//    /**
//     * 清空登录日志
//     */
//    @ApiOperation(value = "清空登录日志")
//    @DeleteMapping("/clean")
//    public Result<Void> clean() {
//        boolean result = loginLogService.cleanLoginLog();
//        return result ? Result.success() : Result.failed("清空登录日志失败");
//    }
} 